<?php

/**
 * 资讯 API
 * User: don
 */

namespace app\modules\app\controllers;

use app\modules\app\models\UserPlan;
use app\modules\cn\models\HotActive;
use app\modules\content\models\Active;
use yii;
use app\libs\AppControl;

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With');
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

class IndexController extends AppControl
{

    public $enableCsrfValidation = false;

    function init()
    {
        parent::init();
        include_once($_SERVER['DOCUMENT_ROOT'] . '/../libs/ucenter/ucenter.php');
    }

    public function actionPlanData()
    {
        $uid = Yii::$app->session->get("uid");
        if ($uid == false) {
            die(json_encode(['message' => '未登录', 'code' => 5]));
        }
        $data = UserPlan::find()->asarray()->where('uid=' . $uid)->orderby('id desc')->one();
        $active=Active::find()->asArray()->orderBy('id desc')->one();
        $hotactive = HotActive::find()->where(['type'=>1])->orderBy('id desc')->asArray()->limit(2)->all();
        die(json_encode(['code' => 1, 'data' =>['data'=> $data,'status'=>$data!=false?1:0,'active'=>$active,'hotactive'=>$hotactive]]));
    }
}